package com.ruoyi.wechat.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.wechat.domain.*;
import com.ruoyi.wechat.service.ICampFacilityService;
import com.ruoyi.wechat.service.IFacilityService;
import com.ruoyi.wechat.service.IFacilityTypeService;
import com.ruoyi.wechat.service.IWxFacilityTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wechat/facility")
public class WxFacilityController extends BaseController {
//    @Autowired
//    private ICampFacilityService campFacilityService;

    @Autowired
    private IWxFacilityTypeService wxFacilityTypeService;

    /**
     * 获得服务设施类型及服务设施列表
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list() {

        List<FacilityTypeVO> list = wxFacilityTypeService.selectTypeAndFacility();
        return success(list);
    }

    /**
     * 根据营地Id查询该营地的服务设施列表
     * @param campId
     * @return
     */
    @GetMapping("/getInfo/{campId}")
    public AjaxResult getInfo(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<FacilityTypeVO> list = wxFacilityTypeService.campFacilityListByCampId(campId);
        return success(list);
    }

    /**
     * 根据营地Id和服务设施Id集合完成批量添加
     * @param wxCampFacilityVo
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxCampFacilityVo wxCampFacilityVo){
        if (wxCampFacilityVo.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxCampFacilityVo.getFacilityIds() == null) {
            return error("服务设施Id不能为空");
        }
        return toAjax(wxFacilityTypeService.insertCampFacility(wxCampFacilityVo.getCampId(), wxCampFacilityVo.getFacilityIds()));
    }

    /**
     * 根据营地Id完成删除
     * @param campId
     * @return
     */
    @DeleteMapping("/delete/{campId}")
    public AjaxResult delete(@PathVariable("campId") String campId){
        if (campId == null) {
            return error("营地Id不能为空");
        }
        return toAjax(wxFacilityTypeService.deleteCampFacilityByCampId(campId));
    }
//    @GetMapping("/list")
//    public AjaxResult list() {
//        FacilityType facilityType = new FacilityType();
//        List<FacilityType> list = campFacilityService.facilityTypeList(facilityType);
//        return success(list);
//    }
}